package com.ice.work.moment.facade.ticket.controller.fallback;

import com.honeybee.cloud.framework.base.exception.business.BaseBizException;
import com.honeybee.cloud.framework.base.exception.service.ServiceExceptionBase;
import com.honeybee.cloud.framework.base.exception.service.ServiceExceptionEnum;
import com.honeybee.cloud.framework.common.page.Page;
import com.honeybee.cloud.framework.common.response.ResponseEntity;
import com.ice.work.moment.facade.ticket.controller.IUserController;
import com.ice.work.moment.facade.ticket.dto.PassengerDTO;
import com.ice.work.moment.facade.ticket.request.LoginRequest;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

/**
 * @Description 回退
 * @Author DELL
 * @Create 2018-12-10
 * @Since 1.0.0
 */
@Slf4j
@SuppressWarnings("all")
public abstract class UserHystrixFallbackFactory implements FallbackFactory<IUserController> {
    @Override
    public IUserController create(Throwable throwable) {
        log.error("服务调用异常", throwable);
        return new IUserController() {
            @Override
            public ResponseEntity<String> login(LoginRequest request) {
                return getInstance();
            }

            @Override
            public ResponseEntity<Void> out(String appKey) {
                return getInstance();
            }

            @Override
            public ResponseEntity<Page<PassengerDTO>> queryPassengers(Long page, Long size, String appKey) throws BaseBizException {
                return getInstance();
            }

        };
    }

    protected ResponseEntity getInstance() {
        return ResponseEntity.error(ServiceExceptionBase.getInstance(ServiceExceptionEnum.MOMENT_TICKET_SERVICE));
    }
}
